package com.ruoyi.web.controller.biz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.biz.enums.CostTypeEnum;
import com.ruoyi.biz.model.req.CostProjectReq;
import com.ruoyi.biz.model.resp.BizCostResp;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.biz.domain.BizCost;
import com.ruoyi.biz.service.BizCostService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成本开支Controller
 * 
 * @author tianl
 * @date 2025-01-01
 */
@RestController
@RequestMapping("/biz/bizCost")
public class BizCostController extends BaseController {
    @Autowired
    private BizCostService bizCostService;
    @GetMapping(value = "/listCostType")
    public AjaxResult listCostType() {
        return success(CostTypeEnum.toList());
    }

    /**
     * 成本开支全部列表
     */
    @GetMapping(value = "/listAll")
    public AjaxResult listAll(CostProjectReq bizCost) {
        return success(bizCostService.list(bizCost));
    }

    /**
     * 查询成本开支列表
     */
    
    @GetMapping("/list")
    public TableDataInfo list(CostProjectReq bizCost) {
        return getDataTable(bizCostService.listPage(bizCost));
    }

    /**
     * 导出成本开支列表
     */
    
    @Log(title = "成本开支", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CostProjectReq bizCost) {
        List<BizCostResp> list = bizCostService.list(bizCost);
        ExcelUtil<BizCostResp> util = new ExcelUtil<>(BizCostResp.class);
        util.exportExcel(response, list, "成本开支数据");
    }

    /**
     * 获取成本开支详细信息
     */
    
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bizCostService.selectById(id));
    }

    /**
     * 新增成本开支
     */
    
    @Log(title = "成本开支", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCost bizCost) {
        bizCostService.beforeSave(bizCost,true);
        return AjaxResult.success();
    }

    /**
     * 修改成本开支
     */
    
    @Log(title = "成本开支", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCost bizCost) {
        bizCostService.beforeSave(bizCost,true);
        return AjaxResult.success();
    }

    /**
     * 删除成本开支
     */
    
    @Log(title = "成本开支", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        bizCostService.deleteByIds(ids);
        return AjaxResult.success();
    }
}
